<#include "/WEB-INF/template/common/macro/base.ftl"/>
<#include "/WEB-INF/template/common/macro/libs.ftl"/>
<#include "/WEB-INF/template/common/layout/l_admin.ftl"/>
<@adminLayout>
    <@breadcrumb view=breadcrumbView/>
<div class="row">
    <div class="col-md-12">
        <!-- BEGIN EXAMPLE TABLE PORTLET-->
        <div class="portlet box light-grey">
            <div class="portlet-title">
                <div class="caption"><i class="fa fa-globe"></i>${breadcrumbView.getCurmenu().name!}</div>
                <div class="actions">
                    <button id="list_add" class="btn blue" data-toggle="modal">
                        <i class="fa fa-plus-circle"></i>
                        添加
                    </button>
                </div>
            </div>
            <div class="portlet-body">
                <div class="table-toolbar">
                    <div class="">
                        <div class="note note-info">
                            <h5>说明:软件更新配置文件以【记录】的【状态】为 <a class="btn btn-xs green">启用</a>的记录为准!</h5>

                            <p>
                                软件更新路径:<span style="padding-left:20px;"><a
                                    href="${CONTEXT_PATH}/m/appupdate/u" class="alert-success">[站点]/m/appupdate/u</a><span>
                            </p>
                        </div>
                    </div>
                </div>
                <table class="table table-striped table-bordered table-hover" style="width:100%"
                       id="sample_1">
                    <thead>
                    <tr>
                        <th width="5%">ID</th>
                        <th width="5%">版本号</th>
                        <th width="30%">内容</th>
                        <th width="30%">备注</th>
                        <th width="10%">程序</th>
                        <th width="5%">状态</th>
                        <th width="10%">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                        <#list list as item>
                        <tr>
                            <td>${item.id}</td>
                            <td>${item.version}</td>
                            <td>${item.content}</td>
                            <td>${item.remark}</td>
                            <td>
                                <#if item.apkurl!>
                                    <a href="${CONTEXT_PATH}/${item.apkurl}" class="btn btn-xs green">
                                        <i class="fa fa-android apkurl"></i>
                                    </a>
                                </#if>
                                <#if item.iosurl>
                                    <a href="${CONTEXT_PATH}/${item.iosurl}" class="btn btn-xs default">
                                        <i class="fa fa-apple iosurl"></i>
                                    </a>
                                </#if>
                            </td>
                            <td>
                                <#if item.liveflag==1>
                                    <span class="badge badge-success badge-roundless">
                                        启用
                                    </span>
                                </#if>
                                <#if item.liveflag==0>
                                    <span class="badge badge-default badge-roundless">
                                        停用
                                    </span>
                                </#if>
                            </td>
                            <td>
                                <a href="javascript:;" onclick="update(this,'${item.uuid}')"
                                   class="btn btn-primary btn-xs">
                                    <i class="fa fa-pencil update"></i>
                                </a>
                                <a href="javascript:;" onclick="setOK(this,'${item.uuid}')"
                                   class="btn btn-xs yellow">
                                    <i class="fa fa-check check"></i>
                                </a>
                                <a href="javascript:;" onclick="deletebyid(this,'${item.uuid}')"
                                   class="btn btn-xs default">
                                    <i class="fa fa-minus-circle "></i>
                                </a>
                            </td>
                        </tr>
                        </#list>
                    </tbody>
                </table>
            </div>
        </div>
        <!-- END EXAMPLE TABLE PORTLET-->
    </div>
    <!--model begin-->
    <@Modal_CURD "ajax_add"/>
    <@Modal_CURD "ajax_update"/>
    <@Modal_SystemOpera/>
    <!--model end-->
</div>
    <@script>
        <@libs_datatables/>
    <script type="text/javascript">

        jQuery(document).ready(function () {
            $('#sample_1').dataTable({
                "sPaginationType": "bootstrap",
                "aLengthMenu": [[5, 10, 20, -1], [5, 10, 20, "所有"]],
                "iDisplayLength": 5
            });

            $("#sample_1_filter input[type='text']").addClass("form-control input-small");
            var addobj = $.extend(CONST_ACTION.ADD, {
                modaldom: $("#ajax_add"),
                actiondom: $("#list_add"),
                actionurl: "${CONTEXT_PATH}/m/appupdate/add"
            });
            //Add action setting
            setFormAjaxAction(addobj);
        });
        /**
         * 激活最新版本
         * @param obj
         * @param id
         */
        function setOK(obj, id) {
            var cfg = $.extend(CONST_ACTION.DELETE, {
                msg: "确定激活当前版本?",
                actiondom: $(obj),
                actionurl: "${CONTEXT_PATH}/m/appupdate/effect/" + id,
                okevent: function (config) {
                    var modal = $("#" + config.modaldom);
                    var url = config.actionurl || "";
                    $.getJSON(url, function (data, status, xhr) {
                        if (data.status) {
                            toastr.success(data.msg, '操作提示');
                            $(modal).modal('hide');
                            window.location.reload();
                        } else {
                            toastr.error(data.msg, '操作提示');
                        }
                    });
                }
            })
            SystemConfirm(cfg);
        }
        function update(obj, id) {
            var updateobj = $.extend(CONST_ACTION.UPDATE, {
                modaldom: $("#ajax_update"),
                actiondom: $(obj),
                actionurl: "${CONTEXT_PATH}/m/appupdate/edit/" + id
            });
            //Update action setting
            updateEvent(updateobj);
        }
        function deletebyid(obj, id) {
            var cfg = $.extend(CONST_ACTION.DELETE, {
                actiondom: $(obj),
                actionurl: "${CONTEXT_PATH}/m/appupdate/delete/" + id
            })
            SystemConfirm(cfg)
        }
    </script>
    </@script>
</@adminLayout>
